#include "bsp_pwm.h"

/**
 * @description: 开启PWM输出通道
 * @param {uint8_t} _pwm-PWM通道选择
 * @return {NONE}
 */
void bsp_pwm_on(uint8_t _pwm)
{
    switch (_pwm)
    {
        case PWM_CHANNEL1:
		    HAL_TIM_PWM_Start(&htim14,TIM_CHANNEL_1);   /* 开启定时器14通道1 PWM输出 */
            break;
        case PWM_CHANNEL2:
		    HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_4);    /* 开启定时器3通道4 PWM输出 */
            break;
        default:
            break;
    }
}

/**
 * @description: 关闭PWM通道输出
 * @param {uint8_t} _pwm-PWM通道选择
 * @return {NONE}
 */
void bsp_pwm_off(uint8_t _pwm)
{
    switch (_pwm)
    {
        case PWM_CHANNEL1:
		    HAL_TIM_PWM_Stop(&htim14,TIM_CHANNEL_1);   /* 关闭定时器14通道1 PWM输出 */
            break;
        case PWM_CHANNEL2:
		    HAL_TIM_PWM_Stop(&htim3,TIM_CHANNEL_4);    /* 关闭定时器3通道4 PWM输出 */
            break;
        default:
            break;
    }
}

/**
 * @description: PWM输出占空比控制
 * @param {uint8_t} _pwm-PWM通道选择
 * @param {uint32_t} _cmp_val-PWM占空比控制0-1000
 * @return {NONE}
 */
void bsp_pwm_set_cmp(uint8_t _pwm, uint32_t _cmp_val)
{
	if(_cmp_val > MAX_PWM_CMP)
	{
		_cmp_val = MAX_PWM_CMP;
	}
    switch (_pwm)
    {
        case PWM_CHANNEL1:
		    __HAL_TIM_SetCompare(&htim14, TIM_CHANNEL_1, _cmp_val);     /* 设置定时器14通道1的比较值· */
            break;
        case PWM_CHANNEL2:
		    __HAL_TIM_SetCompare(&htim3, TIM_CHANNEL_4, _cmp_val);      /* 设置定时器3通道4的比较值· */
            break;
        default:
            break;
    }
}

